package com.eyaomall.wxmall.common.http;

import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.apache.http.nio.client.HttpAsyncClient;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Service;

@Service("httpAsyncClientBuilder")
public class HttpAsyncClientBuilder implements FactoryBean<CloseableHttpAsyncClient> {
	
	private CloseableHttpAsyncClient httpclient = null;

	@Override
	public CloseableHttpAsyncClient getObject() throws Exception {
		if (httpclient == null) {
			httpclient = HttpAsyncClients.createDefault();
			httpclient.start();
		}
		
		return httpclient;
	}

	@Override
	public Class<?> getObjectType() {
		
		return HttpAsyncClient.class;
	}

	@Override
	public boolean isSingleton() {
		
		return true;
	}
}